#ifndef __CM_MEMBER_H__
#define __CM_MEMBER_H__

#include "RtInetAddr.h"
#include "sessbase.h"
#include "cmimdef.h"

enum
{
	Connectivity_Type_None = 0x00,
	Connectivity_Type_Self = 0x01,
	Connectivity_Type_Peer = 0x02,
	Connectivity_Type_Both = 0x03,
	Connectivity_Type_NPeer	= 0x4
};

class RT_API_EXPORT CRtMember
{
public:
	CRtMember();
	CRtMember(const CRtUserID& userid,
				const CRtString& strIP,
				WORD nPort,
				Net_Protocol_Type nType);

	CRtMember(const CRtUserID& userid,
				const CRtString& strIP,
				WORD nPort,
				Net_Protocol_Type nType,
				const CRtString& strDerivedIP,
				WORD nDerivedPort);

	CRtMember(const CRtUserID& userid,
				const CRtInetAddr& addr,
				Net_Protocol_Type nType);

	CRtMember(const CRtUserID& userid,
				const CRtInetAddr& addr,
				Net_Protocol_Type nType,
				const CRtInetAddr& strDerivedAddr);

	CRtMember(const CRtMember& otherMember);
	~CRtMember();

	CRtMember& operator=(const CRtMember& otherMember);
	BOOL operator==(const CRtMember& otherMember) const;

	BOOL IsSameAddress(const CRtInetAddr& addr);
	void SetUserID(const CRtUserID& userid)
	{
		m_userid = userid;
	}
	void SetUserName(const CRtString& username)
	{
		m_userName = username;
	}
	
	void SetAddress(const CRtInetAddr& addr, Net_Protocol_Type nType, BOOL bSamewithDerivedAddr);
	void SetDerivedAddr(const CRtInetAddr& addr);
	
	void SetPriority(DWORD dwPriority)
	{
		m_dwPriority = dwPriority;
	}

	void SetSecurityData(const CRtString& securityData)
	{
		m_SecurityData = securityData;
	}

	void SetConnectivity(BYTE nType);//{m_ConnectivityType = nType;}

	const CRtInetAddr& GetAddress()const{return m_Address;	}
	const CRtInetAddr& GetDerivedAddr()const{return m_DerivedAddr;}
	Net_Protocol_Type GetType()const {return m_nType;	}
	DWORD GetPriority() const{return m_dwPriority;}
	const CRtString& GetSecurityData() const{return m_SecurityData;}
	BYTE GetConnectivity() const{return m_ConnectivityType;}
	const CRtUserID& GetUserID()const{return m_userid;}
	const CRtString& GetUserName() const{return m_userName;}
	
	BOOL IsPublishIP() const
	{
		return m_Address.GetIpAddrIn4Bytes() == m_DerivedAddr.GetIpAddrIn4Bytes();
	}

	LONGLONG GetCheckTime() const{return m_dwCheckTime;}
	void SetCheckTime(LONGLONG dwTimeTick){m_dwCheckTime = dwTimeTick;}

protected:
	void Set(const CRtMember& otherMember);
protected:
	CRtInetAddr		m_Address;
	Net_Protocol_Type	m_nType;
	CRtInetAddr		m_DerivedAddr;
	WORD	m_ConnectivityType;
	CRtUserID		m_userid;
	CRtString			m_userName;
	CRtString		m_SecurityData;
	DWORD			m_dwPriority;
	LONGLONG		m_dwCheckTime;
};

#endif//!__CM_MEMBER_H__
